package com.game.league.web;

import android.view.ViewGroup;

import com.game.base.app.base.BaseFragment;
import com.game.base.x5.web.WebPanel;
import com.game.league.R;
import com.game.league.databinding.FragmentWebBinding;


/**
 * 网页容器fragment
 * <p>
 * 调用：etSupportFragmentManager().beginTransaction().replace(R.id.main_framelayout, (BaseFragment) result.get()).commit();
 * <p>
 * Created by  Su on 2018/12/13.
 */
public class WebFragment extends BaseFragment<FragmentWebBinding> {
    private WebPanel webPanel;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_web;
    }

    @Override
    protected void initView() {
    }

    @Override
    protected void initData() {
        addView(binding.webContainer);
    }

    private void addView(ViewGroup viewGroup) {
        String url = "";
        String data = "";
        if (mBundle != null) {
            url = mBundle.getString("url");
            data = mBundle.getString("data");
        }
        webPanel = new WebPanel(getActivity(), url, data);
        viewGroup.removeAllViews();
        viewGroup.addView(webPanel.getContentView());
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
    }

    @Override
    public void onResume() {
        super.onResume();
        if (webPanel != null) {
            webPanel.getWebView().onResume();
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        if (webPanel != null) {
            webPanel.getWebView().onPause();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (webPanel != null) webPanel.onDestroy();
    }
}
